package com.lipaluma.test.db.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.lipaluma.test.db.internal.DialectEnum;

/**
 * Annotation permits to load files by a Load Data Infile. 
 * <p>
 * Define one folder path and each file in the folder will be loaded in one table on the database.
 * <p>
 * The name of the file has to be named like : <br>
 * <b> - [name_schema.]name_table[.ext]</b>
 * 
 * <ul>
 * <li>The <b><i>name_schema</i></b> is optional depending if the data source knows the schema or not.</li>
 * <li><b><i>name_table</i></b> is the name of the table in the database to load.</li>
 * <li><b><i>ext</i></b> is the extension of the file. Any extension is accepted. <br/>
 * But files will be sorted by the extension to load in order.</li>
 * </ul>
 * 
 * For example : <br/>
 * In folder, we have 2 files : mySchema.my_table1.dat1 and mySchema.my_table2.dat2.
 * Then, the dat1 file will be loaded before the dat2 file. 
 * 
 * @author Mario
 */
@Documented
@Inherited
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface LoadDataInfile {

	/**
	 * Path of the folder who contains files to load into the database
	 */
	String value();
	
	/**
	 * Separator between each field in files to load
	 */
	String fieldDelim() default ",";

	/**
	 * Character that enclosed each field
	 */
	String fieldEnclosed() default "";

	/**
	 * Character that delimites the end of the line in files
	 */
	String linesDelim() default "\n";

	/**
	 * indicates if files have an header with the names of fields of the table to load in database
	 */
	boolean headers() default false;

	/**
	 * Define the dialect for the load data request
	 * @return
	 */
	DialectEnum dialect() default DialectEnum.MYSQL;
	
	/**
	 * Define the datasource name to use for inject data
	 * @return
	 */
	String dataSource() default "";

	/**
	 * Used for define more than one folder path to load
	 * @author Mario
	 */
	@Documented
	@Inherited
	@Target({ElementType.METHOD, ElementType.TYPE})
	@Retention(RetentionPolicy.RUNTIME)
	public @interface List {

		LoadDataInfile[] value();
	}

}
